The stream classes derived from class _iiii_oooo_ssss provide a high level interface
that supports transferring formatted and unformatted information into and
out of _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffffs. This manual page describes the operations common to
both input and output.
Several enumerations are declared in class _iiii_oooo_ssss, _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee, _iiii_oooo______ssss_tttt_aaaa_tttt_eeee,
_ssss_eeee_eeee_kkkk______dddd_iiii_rrrr, and format flags, to avoid polluting the global name space.
The _iiii_oooo______ssss_tttt_aaaa_tttt_eeees are described on this manual page under ``Error States.''
The format fields are also described on this page, under ``Formatting.''
The _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeees are described in detail in _ffff_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++) under _oooo_pppp_eeee_nnnn_((((_)))).
The _ssss_eeee_eeee_kkkk______dddd_iiii_rrrrs are described in _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++) under _ssss_eeee_eeee_kkkk_oooo_ffff_ffff_((((_)))).
In the following descriptions assume:
- _s and _s_2 are _iiii_oooo_sssss.
- _s_r is an _iiii_oooo_ssss_&&&&.
- _s_p is a _iiii_oooo_ssss_****.
- _i, _o_i, _j, and _n are _iiii_nnnn_tttts.
- _l, _f, and _b are _llll_oooo_nnnn_ggggs.
- _c and _o_c are _cccc_hhhh_aaaa_rrrrs.
- _o_s_p and _o_o_s_p are _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_****s.
- _s_b is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_****.
- _p_o_s is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss.
- _o_f_f is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_oooo_ffff_ffff.
- _d_i_r is a _ssss_eeee_eeee_kkkk______dddd_iiii_rrrr.
- _m_o_d_e is an _iiii_nnnn_tttt representing an _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee.
- _f_c_t is a function with type _iiii_oooo_ssss_&&&& _((((_****_))))_((((_iiii_oooo_ssss_&&&&_)))).
Stores _i as the error state. If _i is zero, this clears all
bits. To set a bit without clearing previously set bits
requires something like _s_...._cccc_llll_eeee_aaaa_rrrr_((((_iiii_oooo_ssss_::::_::::_bbbb_aaaa_dddd_bbbb_iiii_tttt_||||_ssss_...._rrrr_dddd_ssss_tttt_aaaa_tttt_eeee_((((_))))_)))).
_i_====_s_...._gggg_oooo_oooo_dddd_((((_))))
Returns non-zero if the error state has no bits set, zero
otherwise.
_i_====_s_...._eeee_oooo_ffff_((((_))))
Returns non-zero if _eeee_oooo_ffff_bbbb_iiii_tttt is set in the error state, zero
otherwise. Normally this bit is set when an end-of-file has
been encountered during an extraction.
_i_====_s_...._ffff_aaaa_iiii_llll_((((_))))
Returns non-zero if either _bbbb_aaaa_dddd_bbbb_iiii_tttt or _ffff_aaaa_iiii_llll_bbbb_iiii_tttt is set in the
error state, zero otherwise. Normally this indicates that some
extraction or conversion has failed, but the stream is still
usable. That is, once the _ffff_aaaa_iiii_llll_bbbb_iiii_tttt is cleared, I/O on _s can
usually continue.
_i_====_s_...._bbbb_aaaa_dddd_((((_))))
Returns non-zero if _bbbb_aaaa_dddd_bbbb_iiii_tttt is set in the error state, zero
otherwise. This usually indicates that some operation on
_s_...._rrrr_dddd_bbbb_uuuu_ffff_((((_)))) has failed, a severe error, from which recovery is
probably impossible. That is, it will probably be impossible
Two operators are defined to allow convenient checking of the error state
of an _iiii_oooo_ssss: _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr_!!!!_((((_)))) and _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr _vvvv_oooo_iiii_dddd_****_((((_)))). The latter converts an _iiii_oooo_ssss
to a pointer so that it can be compared to zero. The conversion will
return 0 if _ffff_aaaa_iiii_llll_bbbb_iiii_tttt or _bbbb_aaaa_dddd_bbbb_iiii_tttt is set in the error state, and will return
a pointer value otherwise. This pointer is not meant to be used. This
An _iiii_oooo_ssss has a _f_o_r_m_a_t _s_t_a_t_e that is used by input and output operations to
control the details of formatting operations. For other operations the
format state has no particular effect and its components may be set and
examined arbitrarily by user code. Most formatting details are
controlled by using the _ffff_llll_aaaa_gggg_ssss_((((_)))), _ssss_eeee_tttt_ffff_((((_)))), and _uuuu_nnnn_ssss_eeee_tttt_ffff_((((_)))) functions to set
the following flags, which are declared in an enumeration in class _iiii_oooo_ssss.
Three other components of the format state are controlled separately with
the functions _ffff_iiii_llll_llll_((((_)))), _wwww_iiii_dddd_tttt_hhhh_((((_)))), and _pppp_rrrr_eeee_cccc_iiii_ssss_iiii_oooo_nnnn_((((_)))).
_ssss_kkkk_iiii_pppp_wwww_ssss
If _ssss_kkkk_iiii_pppp_wwww_ssss is set, whitespace will be skipped on input. This
applies to scalar extractions. When _ssss_kkkk_iiii_pppp_wwww_ssss is not set,
whitespace is not skipped before the extractor begins
conversion. If _ssss_kkkk_iiii_pppp_wwww_ssss is not set and a zero length field is
encountered, the extractor will signal an error. Additionally,
the arithmetic extractors will signal an error if _ssss_kkkk_iiii_pppp_wwww_ssss is not
set and a whitespace is encountered.
_llll_eeee_ffff_tttt
_rrrr_iiii_gggg_hhhh_tttt
_iiii_nnnn_tttt_eeee_rrrr_nnnn_aaaa_llll
These flags control the padding of a value. When _llll_eeee_ffff_tttt is set,
the value is left-adjusted, that is, the fill character is
added after the value. When _rrrr_iiii_gggg_hhhh_tttt is set, the value is right-
adjusted, that is, the fill character is added before the
value. When _iiii_nnnn_tttt_eeee_rrrr_nnnn_aaaa_llll is set, the fill character is added after
any leading sign or base indication, but before the value.
Right-adjustment is the default if none of these flags is set.
These fields are collectively identified by the static member,
_iiii_oooo_ssss_::::_::::_aaaa_dddd_jjjj_uuuu_ssss_tttt_ffff_iiii_eeee_llll_dddd. The fill character is controlled by the
_ffff_iiii_llll_llll_((((_)))) function, and the width of padding is controlled by the
static member _iiii_oooo_ssss_::::_::::_ffff_llll_oooo_aaaa_tttt_ffff_iiii_eeee_llll_dddd.
_uuuu_nnnn_iiii_tttt_bbbb_uuuu_ffff
When set, a flush is performed by _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_::::_::::_oooo_ssss_ffff_xxxx_((((_)))) after each
insertion. Unit buffering provides a compromise between
buffered output and unbuffered output. Performance is better
under unit buffering than unbuffered output, which makes a
system call for each character output. Unit buffering makes a
system call for each insertion operation, and doesn't require
the user to call _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_::::_::::_ffff_llll_uuuu_ssss_hhhh_((((_)))).
_ssss_tttt_dddd_iiii_oooo
When set, _ssss_tttt_dddd_oooo_uuuu_tttt and _ssss_tttt_dddd_eeee_rrrr_rrrr are flushed by _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_::::_::::_oooo_ssss_ffff_xxxx_((((_))))
after each insertion.
The following functions use and set the format flags and variables.
_o_c_====_s_...._ffff_iiii_llll_llll_((((_c_))))
Sets the ``fill character'' format state variable to _c and
returns the previous value. _c will be used as the padding
character, if one is necessary (see _wwww_iiii_dddd_tttt_hhhh(), below). The
default fill or padding character is a space. The positioning
of the fill character is determined by the _rrrr_iiii_gggg_hhhh_tttt, _llll_eeee_ffff_tttt, and
_iiii_nnnn_tttt_eeee_rrrr_nnnn_aaaa_llll flags; see above. A parameterized manipulator,
_ssss_eeee_tttt_ffff_iiii_llll_llll, is also available for setting the fill character; see
_mmmm_aaaa_nnnn_iiii_pppp(3C++).
_c_====_s_...._ffff_iiii_llll_llll_((((_))))
Returns the ``fill character'' format state variable.
Resets in _s only the format flags specified by _f to the
settings marked in _b, and returns the previous settings. That
is, the format flags specified by _f are cleared in _s, then
reset to be those marked in _b. For example, to change the
conversion base in _s to be _hhhh_eeee_xxxx, one could write:
_s_...._ssss_eeee_tttt_ffff_((((_iiii_oooo_ssss_::::_::::_hhhh_eeee_xxxx_,,,,_iiii_oooo_ssss_::::_::::_bbbb_aaaa_ssss_eeee_ffff_iiii_eeee_llll_dddd_)))). _iiii_oooo_ssss_::::_::::_bbbb_aaaa_ssss_eeee_ffff_iiii_eeee_llll_dddd specifies the
conversion base bits as candidates for change, and _iiii_oooo_ssss_::::_::::_hhhh_eeee_xxxx
specifies the new value. _s_...._ssss_eeee_tttt_ffff_((((_0000_,,,,_f_)))) will clear all the bits
specified by _f, as will a parameterized manipulator,
_rrrr_eeee_ssss_eeee_tttt_iiii_oooo_ssss_ffff_llll_aaaa_gggg_ssss; see _mmmm_aaaa_nnnn_iiii_pppp(3C++).
Class _iiii_oooo_ssss can be used as a base class for derived classes that require
additional format flags or variables. The iostream library provides
several functions to do this. The two static member functions
_iiii_oooo_ssss_::::_::::_xxxx_aaaa_llll_llll_oooo_cccc and _iiii_oooo_ssss_::::_::::_bbbb_iiii_tttt_aaaa_llll_llll_oooo_cccc, allow several such classes to be used
Solves problems that arise when mixing stdio and iostreams.
The first time it is called it will reset the standard
iostreams (_cccc_iiii_nnnn, _cccc_oooo_uuuu_tttt, _cccc_eeee_rrrr_rrrr, _cccc_llll_oooo_gggg) to be streams using
_ssss_tttt_dddd_iiii_oooo_bbbb_uuuu_ffffs. After that, input and output using these streams
may be mixed with input and output using the corresponding
_FFFF_IIII_LLLL_EEEEs (_ssss_tttt_dddd_iiii_nnnn, _ssss_tttt_dddd_oooo_uuuu_tttt, and _ssss_tttt_dddd_eeee_rrrr_rrrr) and will be properly
synchronized. _ssss_yyyy_nnnn_cccc______wwww_iiii_tttt_hhhh______ssss_tttt_dddd_iiii_oooo_((((_)))) makes _cccc_oooo_uuuu_tttt and _cccc_eeee_rrrr_rrrr unit
buffered (see _iiii_oooo_ssss_::::_::::_uuuu_nnnn_iiii_tttt_bbbb_uuuu_ffff and _iiii_oooo_ssss_::::_::::_ssss_tttt_dddd_iiii_oooo above). Invoking
_ssss_yyyy_nnnn_cccc______wwww_iiii_tttt_hhhh______ssss_tttt_dddd_iiii_oooo_((((_)))) degrades performance a variable amount,
depending on the length of the strings being inserted (shorter
Extracts whitespace characters. See _iiii_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
_s_r_<<<<_<<<<_eeee_nnnn_dddd_llll
Ends a line by inserting a newline character and flushing. See
_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
_s_r_<<<<_<<<<_eeee_nnnn_dddd_ssss
Ends a string by inserting a null (0) character. See
_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
_s_r_<<<<_<<<<_ffff_llll_uuuu_ssss_hhhh
Flushes _oooo_uuuu_tttt_ssss. See _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
Several parameterized manipulators that operate on _iiii_oooo_ssss objects are
described in _mmmm_aaaa_nnnn_iiii_pppp(3C++): _ssss_eeee_tttt_wwww, _ssss_eeee_tttt_ffff_iiii_llll_llll, _ssss_eeee_tttt_pppp_rrrr_eeee_cccc_iiii_ssss_iiii_oooo_nnnn, _ssss_eeee_tttt_iiii_oooo_ssss_ffff_llll_aaaa_gggg_ssss, and
The _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff associated with an _iiii_oooo_ssss may be manipulated by other methods
than through the _iiii_oooo_ssss. For example, characters may be stored in a
queuelike _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff through an _oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm while they are being fetched
through an _iiii_ssss_tttt_rrrr_eeee_aaaa_mmmm. Or for efficiency some part of a program may choose
to do _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff operations directly rather than through the _iiii_oooo_ssss. In most
cases the program does not have to worry about this possibility, because
an _iiii_oooo_ssss never saves information about the internal state of a _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff.
For example, if the _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is repositioned between extraction
operations the extraction (input) will proceed normally.
CCCCAAAAVVVVEEEEAAAATTTTSSSS
The need for _ssss_yyyy_nnnn_cccc______wwww_iiii_tttt_hhhh______ssss_tttt_dddd_iiii_oooo is a wart. The old stream package did this
as a default, but in the iostream package unbuffered _ssss_tttt_dddd_iiii_oooo_bbbb_uuuu_ffffs are too
inefficient to be the default.
The stream package had a constructor that took a _FFFF_IIII_LLLL_EEEE_**** argument. This is
now replaced by _ssss_tttt_dddd_iiii_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm. It is not declared even as an obsolete form
to avoid having _iiii_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_...._hhhh depend on _ssss_tttt_dddd_iiii_oooo_...._hhhh.
The old stream package allowed copying of streams. This is disallowed by
the iostream package. However, objects of type _iiii_ssss_tttt_rrrr_eeee_aaaa_mmmm______wwww_iiii_tttt_hhhh_aaaa_ssss_ssss_iiii_gggg_nnnn,
_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm______wwww_iiii_tttt_hhhh_aaaa_ssss_ssss_iiii_gggg_nnnn, and _iiii_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm______wwww_iiii_tttt_hhhh_aaaa_ssss_ssss_iiii_gggg_nnnn can be assigned to. Old code
using copying can usually be rewritten to use pointers or these classes.
(The standard streams _cccc_iiii_nnnn, _cccc_oooo_uuuu_tttt, _cccc_eeee_rrrr_rrrr, and _cccc_llll_oooo_gggg are members of
``withassign'' classes, so they can be assigned to, as in